package com.maben.uniapp_back;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 项目启动类
 */
@SpringBootApplication
@Slf4j
@RestController
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
        log.info("************启动成功************");
    }

    @GetMapping("test_list")
    public Object test_list(String pageSize,String currentPage){
        final List<Map<String,Object>> result = new ArrayList<>();
        int length = 100;
        int start = 0;
        if (StringUtils.isNotBlank(pageSize) && StringUtils.isNotBlank(currentPage)){
            final int currentPageInt = Integer.parseInt(currentPage);
            final int pageSizeInt = Integer.parseInt(pageSize);
            start = (currentPageInt-1)*pageSizeInt;
            int tmp = start+pageSizeInt;
            length = tmp >=100?100 : tmp;
        }
        for (int i = start; i < length; i++) {
            int id = i;
            result.add(new HashMap<String,Object>(){{
                put("id", id);
                put("title","标题"+id);
                put("content","评论内容"+id);
            }});
        }
        return result;
    }

    @GetMapping("test_detail")
    public Object test_detail(String id){
        return new HashMap<String,Object>(){{
            put("id",id);
            put("title","标题"+id);
            put("content","评论内容"+id);
            put("time",new Date());
            put("author","张三");
        }};
    }
}
